//
//  FrontViewController.m
//  Prospectus
//
//  Created by Ken Power on 01/02/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "FrontViewController.h"

#import "ListofDepartmentsViewController.h"
#import "DepartmentViewController.h"
#import "DataAccess.h"

@implementation FrontViewController

@synthesize btnProspectus;
@synthesize btnComputingDepartment;
@synthesize btnBusinessDepartment;

//Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

	
}

- (void)viewWillAppear:(BOOL)animated{
	
[self.navigationController setNavigationBarHidden:YES animated:NO];
}

- (void)viewWillDisappear:(BOOL)animated{
	
	[self.navigationController setNavigationBarHidden:NO animated:YES];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

//DO NOT DELETE, will replace temp code below
-(IBAction)buttonPress:sender{
// Create and push a list of departments view controller.
//	ListofDepartmentsViewController *prospectusViewController = [[ListofDepartmentsViewController alloc] initWithStyle:UITableViewStylePlain];
//       
//	prospectusViewController.managedObjectContext = self.managedObjectContext;
//	
//
//	[self.navigationController pushViewController:prospectusViewController animated:YES];
//	[prospectusViewController release];
}


// this code is temporary, until we get the full database, it just responds to the CAN & BUS buttons on the front page
//
-(IBAction)departmentButtonPress:sender{
	
	NSString *departmentName = @"CAN";
	
	if([sender isEqual:btnBusinessDepartment]){
		departmentName = @"BUS";
	}
	
	// Create and push a department view controller.
	DepartmentViewController *departmentViewController = 
		[[DepartmentViewController alloc] initWithStyle:UITableViewStylePlain];
    

	Department* dept=[DataAccess getDepartment:departmentName];
	if (dept != nil ) {
		departmentViewController.department = dept;
		//departmentViewController.managedObjectContext=[self managedObjectContext];
		[self.navigationController pushViewController:departmentViewController animated:YES];
	}
	else{
		NSLog(@"Department not found, quitting %@",departmentName);
		exit(-1);
	}//department not found, don't attempt to show it
	[departmentViewController release];
}




@end
